<?php
class Notification_model extends CI_Model {
	public function __construct() {
		parent::__construct ();
	}
	public function add($uid, $message, $view_link, $action_message=null, $action_link=null, $cancel_message=null, $cancel_link=null) {
		$data = array (
				'uid' => $uid,
				'message' => $message,
				'view_link' => $view_link,
				'action_message' => $action_message,
				'action_link' => $action_link,
				'cancel_message' => $cancel_message,
				'cancel_link' => $cancel_link 
		);
		$this->db->insert ( 'notification', $data );
	}
	public function delete($nid) {
		$this->db->delete ( 'notification', array (
				'nid' => $nid 
		) );
	}
	public function get($nid) {
		$query = $this->db->get_where ( 'notification', array (
				'nid' => $nid ,'read'=>0
		) );
		if ($query->num_rows () > 0) {
			return $query->row_array ();
		} else {
			return false;
		}
	}
	
	public function get_by_user($uid){
		$query = $this->db->get_where ( 'notification', array (
				'uid' => $uid
		) );
		if ($query->num_rows () > 0) {
			return $query->result_array ();
		} else {
			return false;
		}
	} 
}

?>